﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Validity.Test.Constraints
{
  public class MustNotHaveConstraintTest
  {
    [TestClass]
    public class TrueContext
      : ConstraintTestBase<ObjectStub>
    {
      public class Validator
        : ValidatorBase<ObjectStub>
      {
        public Validator()
        {
          DefineRulesFor(ctx => ctx.MyObjectProperty1).MustNotHave(false);
          DefineRulesFor(ctx => ctx.MyObjectProperty2).MustNotHave(() => false);
          DefineRulesFor(ctx => ctx.MyObjectProperty3).MustNotHave((Object val) => false);
          DefineRulesFor(ctx => ctx.MyObjectProperty4).MustNotHave((ObjectStub obj) => false);
          DefineRulesFor(ctx => ctx.MyObjectProperty5).MustNotHave((obj, val) => false);
        }
      }

      public TrueContext() : base(new Validator(), 5) { }

      [TestMethod]
      public void TestConstraintVerified()
      {
        ValidateConstraintVerfied(new ObjectStub());
      }
    }

    [TestClass]
    public class FalseContext
      : ConstraintTestBase<ObjectStub>
    {
      public class Validator
        : ValidatorBase<ObjectStub>
      {
        public Validator()
        {
          DefineRulesFor(ctx => ctx.MyObjectProperty1).MustNotHave(true);
          DefineRulesFor(ctx => ctx.MyObjectProperty2).MustNotHave(() => true);
          DefineRulesFor(ctx => ctx.MyObjectProperty3).MustNotHave((Object val) => true);
          DefineRulesFor(ctx => ctx.MyObjectProperty4).MustNotHave((ObjectStub obj) => true);
          DefineRulesFor(ctx => ctx.MyObjectProperty5).MustNotHave((obj, val) => true);
        }
      }

      public FalseContext() : base(new Validator(), 5) { }

      [TestMethod]
      public void TestConstraintViolated()
      {
        const String ruleViolation = "Value is invalid";

        ValidateConstraintViolated(new ObjectStub(), ruleViolation);
      }
    }
  }
}
